<script>

// jqGrid所有数据列
var jqgridAllColsArr = ['goodsName', 'goodsSn', 'barCode', 'colorName', 'sizeName', 'categoryName', 'storeStatus',
	'outStorehouseName', 'inStorehouseName', 'blandName', 'orderNo', 'beforeNumber', 'number', 'status',
	'updateTime', 'userName', 'styleName', 'materialName', 'seasonName', 'year', 'storehouseName', 'businessTime', 'remark'];
// 按调拨明细显示的时候的数据列
var detailListShowColsArr = ['amount', 'price', 'orderNo', 'status', 'businessTime', 'outStorehouseName', 'inStorehouseName', 'goodsName', 'goodsSn', 'barCode',
	'colorName', 'sizeName', 'categoryName', 'blandName',
	'number', 'userName', 'styleName', 'materialName', 'seasonName', 'year', 'remark'];
// 按调拨单汇总的数据列
var groupByOrderListShowColsArr = ['amount', 'orderNo', 'status', 'businessTime',
	'outStorehouseName', 'inStorehouseName', 'userName',
	'remark', 'number'];

// 按商品汇总的数据列
var groupByGoodListShowColsArr = ['amount', 'price', 'goodsSn', 'barCode',
	'categoryName', 'blandName',
	'number', 'styleName',
	'materialName', 'seasonName', 'year', 'goodsName'];

// 按仓库汇总的数据列
var groupByStorehouseListShowColsArr = ['amount', 'storehouseName', 'storeStatus', 'number'];

// 调拨明细的查询条件
var detailListSearchItemArr = ['orderNo', 'status', 'userId', 'searchKey', 'category',
	'bland', 'storehouse', 'color', 'size', 'style', 'material', 'year', 'season'];
// 按调拨单汇总的查询条件
var groupByOrderListSearchItemArr = ['orderNo', 'status', 'userId', 'storehouse', 'remark'];


// 按商品汇总的查询条件
var groupByGoodListSearchItemArr = ['searchKey', 'category', 'bland',
	'style', 'material', 'year', 'season', 'status'];
// 按仓库汇总的查询条件
var groupByStorehouseListSearchItemArr = ['status'];

$(document).ready(function () {
	jQuery("#list_section").jqGrid({
		cmTemplate: {
			sortable: false
		},
		jsonReader: {
			root: 'data',
			page: 'current_page',
			total: 'last_page',
			records: 'total'
		},
		prmNames: {},
		postData: {
			beginTime: transferGMTStringtoBJTime(getDayBeginStr(new Date())),
			endTime: transferGMTStringtoBJTime(getOffsetDayBeginStr(new Date(), 1)),
			status: 2
		},
		url: '{{ route('admin.shop.report.allot.transfersRecordDetailList') }}', // 传入后台的地址。
		//mtype: 'post', // 提交后台方式
		datatype: 'json', // 得到后台传入前台的方式
		multiselect: false,
		multiSort: true,
		colModel: [{
			name: 'orderNo',
			index: 'orderNo',
			align: 'center',
			width: 170,
			label: '单号'
		}, {
			name: 'status',
			index: 'status',
			width: 45,
			align: 'center',
			label: '状态'
		}, {
			name: 'businessTime',
			index: 'businessTime',
			width: 120,
			align: 'center',
			label: '调拨时间',
			sortable: true,
			formatter: timeFormat
		}, {
			name: 'goodsName',
			index: 'goodsName',
			align: 'center',
			label: '商品名称',
			frozen: true
			, sortable: true
		}, {
			name: 'goodsSn',
			index: 'goodsSn',
			label: '货号',
			align: 'center',
			width: 100,
			frozen: true
			, sortable: true
		}, {
			name: 'barCode',
			index: 'barCode',
			label: '条码',
			align: "center",
			width: 100,
			frozen: true
		}, {
			name: 'colorName',
			index: 'colorName',
			width: 50,
			label: '颜色',
			align: "center",
			frozen: true
		}, {
			name: 'sizeName',
			index: 'sizeName',
			width: 50,
			label: '尺码',
			align: "center",
			frozen: true
		}, {
			name: 'categoryName',
			index: 'categoryName',
			label: '分类',
			align: "center",
			width: 80
		}, {
			name: 'blandName',
			index: 'blandName',
			label: '品牌',
			align: "center",
			width: 80
		}, {
			name: 'storehouseName',
			index: 'storehouseName',
			label: '仓库',
			align: "center",
			hidden: true,
			width: 50
		}, {
			name: 'storeStatus',
			index: 'storeStatus',
			label: '调出/调入',
			align: "center",
			hidden: true,
			width: 100
		}, {
			name: 'number',
			index: 'number',
			label: "调拨数量",
			align: "center",
			width: 60,
			formatter: 'Integer'
		}, {
			name: 'outStorehouseName',
			index: 'outStorehouseName',
			align: 'center',
			label: '调出仓库'
		}, {
			name: 'inStorehouseName',
			index: 'inStorehouseName',
			align: 'center',
			label: '调入仓库'
		}, {
			name: 'outNumber',
			index: 'outNumber',
			label: "调出数量",
			align: "center",
			hidden: true,
			width: 60,
			formatter: function (value) {
				if (value == undefined) {
					return 0;
				} else {
					return value;
				}
			}
		}, {
			name: 'inNumber',
			index: 'inNumber',
			label: "调入数量",
			hidden: true,
			align: "center",
			width: 60,
			formatter: function (value) {
				if (value == undefined) {
					return 0;
				} else {
					return value;
				}
			}
		}, {
			name: 'price',
			index: 'price',
			label: '单价',
			width: 100,
			align: 'right',
			formatter: 'number'
		}, {
			name: 'amount',
			index: 'amount',
			label: '金额',
			width: 110,
			align: 'right',
			formatter: 'number'
		}, {
			name: 'userName',
			index: 'userName',
			label: '调拨人',
			align: "center",
			width: 50
		}, {
			name: 'styleName',
			index: 'styleName',
			width: 120,
			align: 'center',
			label: '款式'
		}, {
			name: 'materialName',
			index: 'materialName',
			width: 120,
			align: 'center',
			label: '材质'
		}, {
			name: 'seasonName',
			index: 'seasonName',
			label: '季节',
			align: "center",
			width: 80
		}, {
			name: 'year',
			index: 'year',
			label: '年份',
			align: "center",
			formatter: yearFromater,
			width: 90
		}, {
			name: 'remark',
			index: 'remakr',
			label: '备注',
			align: "center",
			width: 150
		}],
		pager: "#list_section_pager", // --得到分页的层
		rownumbers: false, // --是否在表格最前端添加1列为自动编号
		rowNum: 18, // --一页显示几行？
		page: 1, // --从弟几页开始
		rowlist: [10, 20, 30], // --多少页一段
		height: "100%",
		width: "100%",
		viewrecords: true,
		autowidth: true,
		shrinkToFit: false,
		gridComplete: function () {
			$("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
			getScope("StoreReportModule").loadingData = false;
			var dataListType = getScope("StoreReportModule").dataListType;
			// 根据dataListType设置tab
			$("ul#myTab li:not(." + dataListType + ")").removeClass("active").css("background-color", "white");
			$("ul#myTab li." + dataListType).addClass("active");
		},
		loadComplete: function () {
			adjustFrozenColumnHeight('list_section');
			disableTarget(getScope("StoreReportModule").target, false);
		},
		loadError: function () {
			disableTarget(getScope("StoreReportModule").target, false);
		},
	}).jqGrid('navGrid', '#list_section_pager', {
		refresh: false,
		add: false,
		edit: false,
		del: false,
		search: false,
		sortable: false
	}, {
		closeOnEscape: true,
		closeAfterEdit: true
	}, {
		closeOnEscape: true,
		closeAfterAdd: true,
		serializeEditData: function (data) {
			return $.param($.extend({}, data, {
				id: ''
			}));
		}
	});

	// 自适应宽度
	$(window).resize(function () {
		$("#list_section").setGridWidth($("#list_section").parent().parent().parent().parent().parent().width());
	});

	//修复排序列表头样式
	var myGrid = $("#list_section");
	var cm = myGrid[0].p.colModel;
	$.each(myGrid[0].grid.headers, function (index, value) {
		var cmi = cm[index], colName = cmi.name;
		if (cmi.sortable && colName !== 'rn' && colName !== 'cb' && colName !== 'subgrid') {
			$('div.ui-jqgrid-sortable', value.el).addClass('sortable');
			$('div.ui-jqgrid-sortable', value.el).prepend('<span class="sortable-icon"></span>');
		}
	});

	// 设置jqgrid表头对齐方式
	setGridLabelAlign('list_section', 'quantity,price,discount,truePrice,amount,trueAmount,purchasePrice,purchaseAmount,grossProfit,grossProfitRate,trueTotalAmount,alreadyPaid', 'right');
	setGridLabelAlign('list_section', 'goodsName,goodsSn', 'categoryId', 'left');
	setGridLabelClass('list_section', 'quantity,trueAmount,grossProfit,grossProfitRate', 'sortable-align-fix');
	$("#list_section").jqGrid("setLabel", "number", "", {"text-align": "right"});
	$("#list_section").jqGrid("setLabel", "beforeNumber", "", {"text-align": "right"});
	$("#list_section").jqGrid("setLabel", "profitNumber", "", {"text-align": "right"});
	$("#list_section").jqGrid("setLabel", "profitAmount", "", {"text-align": "right"});
	// 冻结列
	jQuery("#list_section").jqGrid('setFrozenColumns');
	adjustFrozenDivHeight('list_section')
	// 设置默认显示列(按明细汇总)
	setGridColDisplay(detailListShowColsArr);
});

/***************************** angularJs模块 ***************************************/
var commodityApp = angular.module('JxApp', ['JxApp.mulsel', "checklist-model", "ui.bootstrap.tpls", 'ui.bootstrap.datepicker', 'JxApp.levelsel']);

commodityApp.controller("StoreReportModule", function ($scope, $filter, $http) {

	$scope.loadingData = false;
	$scope.dataListType = 'storeRecordDetailList';

	$scope.isShowProfitAmount = true;
	$scope.searchModel = {};

	// 初始化状态
	$scope.searchModel.status = 2;
	$scope.storeTransferOrder = {price: null};

	$scope.isShowPrice = false;
	// 查询概况数据
	$scope.getSumData = function (searchParam) {
		if (!searchParam) {
			searchParam = angular.copy($scope.searchParam);
		}
		searchParam.beginTime = getDayBegin($scope.searchModel.beginTime);
		searchParam.endTime = getOffsetDayBegin($scope.searchModel.endTime, 1);
		$scope.sumDataLoading = true;
		$http.get($scope.storeSumReportUrl, {params:searchParam}).success(function (result) {
			$scope.transferCount = result.transferCount;
			$scope.goodsTransferCount = result.goodsTransferCount;
			$scope.inStoreHouse = result.inStoreHouse;
			$scope.transferAllNumber = result.transferAllNumber;
			$scope.outStoreHouse = result.outStoreHouse;
			var p = $scope.storeTransferOrder.price;
			if (p == null || p == undefined || p == '') {
				$scope.transferAmountMoney = "0.00";
			} else {
				// 显示两位小数
				$scope.transferAmountMoney = (result.transferAmountMoney).toFixed(2);
			}
			$scope.sumDataLoading = false;
		});

	};

	$scope.init = function () {
		setGridColDisplay(detailListShowColsArr);

		$scope.searchModel = {timePeriod: 'today', beginTime: new Date(), endTime: new Date(), status: 2};
		$scope.searchParam = {
			beginTime: getDayBeginStr($scope.searchModel.beginTime),
			endTime: getOffsetDayBeginStr($scope.searchModel.endTime, 1), status: 2
		};
		$scope.showCountData = false;
		$scope.showSearchTab = true;
		$scope.storeReportUrl = '{{ route('admin.shop.report.allot.transfersRecordDetailList') }}';
		$scope.storeSumReportUrl = '{{ route('admin.shop.report.allot.ransfersRecordDetailListSum') }}';
		$scope.storehouseMultiSelOptions = [{val: '', text: '-请选择-'}];
		$scope.sumDataLoading = true;
		$scope.allCategory = allCategory;
		$scope.curSearchItemArr = detailListSearchItemArr;
		$scope.blands = strBlandListJson;
		$scope.seasons = strSeasonListJson;
		$scope.allColorJson = allColors;
		$scope.allSizeJson = allSizes;
		$scope.allYears = allYears;
		$scope.allStyleJson = strStyleListJson;

		$scope.getSumData({beginTime: getDayBegin(new Date()), endTime: getOffsetDayBegin(new Date(), 1), status: 2});

		// 根据系统设置判断是否显示金额和单价
		/*$http.post(base + '/admin/system/companyConfig/getCompanyConfigByKey.ac?configKey=storeTransferOrderPrice').success(function (result) {
			if (result.statusCode == 1 && result.object.configValue) {
				$scope.storeTransferOrder.price = result.object.configValue;
				$scope.isShowPrice = true;
			} else {
				$scope.isShowPrice = false;
			}
			showPriceAndAmount('#storeRecordDetailList');
		});*/

	};
	$scope.init();

	$scope.refreshTimePeriod = function () {
		var vToday = new Date();
		if (!$scope.searchModel.beginTime && !$scope.searchModel.endTime) {
			$scope.searchModel.timePeriod = 'all';
		} else if (!$scope.searchModel.beginTime || !$scope.searchModel.endTime) {
			$scope.searchModel.timePeriod = 'other';
		} else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(vToday)
			&& getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(vToday)) {
			$scope.searchModel.timePeriod = 'today';
		} else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(getYesterday(vToday))
			&& getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(getYesterday(vToday))) {
			$scope.searchModel.timePeriod = 'yesterday';
		} else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(addDate(vToday, -6))
			&& getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(new Date())) {
			$scope.searchModel.timePeriod = 'thisWeek';
		} else if (getDayBeginStr($scope.searchModel.beginTime) == getDayBeginStr(addDate(vToday, -29))
			&& getDayBeginStr($scope.searchModel.endTime) == getDayBeginStr(new Date())) {
			$scope.searchModel.timePeriod = 'thisMonth';
		} else {
			$scope.searchModel.timePeriod = 'other';
		}
	};


	/**
	 * 监控事件组件，保持起始时间不要大于结束时间，结束时间不要小于结束时间
	 * */
	$scope.$watch('searchModel.beginTime', function () {
		$scope.refreshTimePeriod();
		if ($scope.searchModel.beginTime != null && $scope.searchModel.endTime != null) {
			if ($scope.searchModel.beginTime > $scope.searchModel.endTime) {
				$scope.searchModel.beginTime = null;
			}
		}
	});

	$scope.$watch('searchModel.endTime', function () {
		$scope.refreshTimePeriod();
		if ($scope.searchModel.beginTime != null && $scope.searchModel.endTime != null) {
			if ($scope.searchModel.endTime < $scope.searchModel.beginTime) {
				$scope.searchModel.endTime = null;
			}
		}
	});

	//查询函数
	$scope.searchList = function () {
		$scope.loadingData = true;
		var categoryIds = getChildIds(allCategoryList, $scope.searchModel.categoryId);
		var vToday = new Date();
		if ($scope.searchModel.timePeriod == 'today') {
			$scope.searchModel.beginTime = vToday;
			$scope.searchModel.endTime = vToday;
		} else if ($scope.searchModel.timePeriod == 'yesterday') {
			var vYesterday = getYesterday(vToday);
			$scope.searchModel.beginTime = vYesterday;
			$scope.searchModel.endTime = vYesterday;
		} else if ($scope.searchModel.timePeriod == 'thisWeek') {
			// 上周的今天再加1天
			$scope.searchModel.beginTime = addDate(vToday, -6);
			$scope.searchModel.endTime = vToday;
		} else if ($scope.searchModel.timePeriod == 'thisMonth') {
			// 算上今天，倒推29天
			$scope.searchModel.beginTime = addDate(vToday, -29);
			$scope.searchModel.endTime = vToday;
		} else if ($scope.searchModel.timePeriod == 'all') {
			$scope.searchModel.beginTime = null;
			$scope.searchModel.endTime = null;
		}


		var searchParam = {
			inStorehouseId: $scope.searchModel.inStorehouseId,
			outStorehouseId: $scope.searchModel.outStorehouseId,
			storehouseId: $scope.searchModel.storehouseId,
			searchKey: $scope.searchModel.searchKey,
			beginTime: transferGMTStringtoBJTime(getDayBeginStr($scope.searchModel.beginTime)),
			endTime: transferGMTStringtoBJTime(getOffsetDayBeginStr($scope.searchModel.endTime, 1)),
			orderNo: $scope.searchModel.orderNo,
			categoryId: categoryIds,
			blandId: $scope.searchModel.blandId,
			status: $scope.searchModel.status,
			userId: $scope.searchModel.userId,
			colorId: $scope.searchModel.colorIds,
			sizeId: $scope.searchModel.sizeIds,
			styleId: $scope.searchModel.styleId,
			year: $scope.searchModel.year,
			remark: $scope.searchModel.remark,
			seasonId: $scope.searchModel.seasonId,
		};

		if (!contains($scope.curSearchItemArr, 'storehouse')) {
			delete searchParam.inStorehouseId;
			delete searchParam.outStorehouseId;
		}
		if (!contains($scope.curSearchItemArr, 'searchKey')) {
			delete searchParam.searchKey;
		}
		if (!contains($scope.curSearchItemArr, 'orderNo')) {
			delete searchParam.orderNo;
		}
		if (!contains($scope.curSearchItemArr, 'category')) {
			delete searchParam.categoryId;
		}
		if (!contains($scope.curSearchItemArr, 'bland')) {
			delete searchParam.blandId;
		}
		if (!contains($scope.curSearchItemArr, 'status')) {
			delete searchParam.status;
		}
		if (!contains($scope.curSearchItemArr, 'userId')) {
			delete searchParam.userId;
		}
		if (!contains($scope.curSearchItemArr, 'color')) {
			delete searchParam.colorId;
		}
		if (!contains($scope.curSearchItemArr, 'size')) {
			delete searchParam.sizeId;
		}
		if (!contains($scope.curSearchItemArr, 'style')) {
			delete searchParam.styleId;
		}

		if (!contains($scope.curSearchItemArr, 'year')) {
			delete searchParam.year;
		}
		if (!contains($scope.curSearchItemArr, 'season')) {
			delete searchParam.seasonId;
		}
		if (!contains($scope.curSearchItemArr, 'remark')) {
			delete searchParam.remark;
		}

		// 手动清空postdata
		$("#list_section").setGridParam({
			postData: null
		});
		$("#list_section").setGridParam({
			postData: {
				page: 1
			}
		});
		//取消上个button禁用
		disableTarget($scope.target, false, true);
		$scope.target = getEvtTarget();
		disableTarget($scope.target, true);
		$("#list_section").jqGrid("setGridParam", {
			postData: searchParam,
			url: $scope.storeReportUrl
			// 传入后台的地址。
		}).trigger("reloadGrid", [{
			page: 1
		}]); // 重新载入Grid表格
		$scope.searchParam = searchParam;//保存最后一次查询结果对应的查询条件,以供用作获取统计数据的查询条件
	};


	$scope.getShowDataCountText = function () {
		if ($scope.showCountData) {
			return '收起统计数据';
		} else {
			return '展示统计数据';
		}
	};

	// 是否显示查询的字段
	$scope.isShowSearchItem = function (itemName) {
		return contains($scope.curSearchItemArr, itemName);
	};

	// 导出报表
	$scope.exportAsExcel = function () {
		var sidxParam = '';
		var sordParam = '';

		var postData = $("#list_section").jqGrid("getGridParam", "postData");

		if (postData.sidx) {
			sidxParam = '&sidx=' + postData.sidx;
		}
		if (postData.sord) {
			sordParam = '&sord=' + postData.sord;
		}
		window.open(base + '/admin/inner/excelImport/report/transferDetailListExcel.ac?jsonUrl=' + $scope.storeReportUrl + sidxParam + sordParam + '&' + $.param($scope.searchParam));
	};

	$scope.helpUrl = GL_CONS.HELP_URL.tranfersReportHelp;
});

/**
 * 标签页切换事件
 */
$('#myTab a').click(function (e) {
	if (getScope("StoreReportModule").loadingData) {
		return;
	}
	e.preventDefault();
	$(this).tab('show');
	// 不同tab页切换时清除排序条件，以免有不存在的列的排序条件时报错(待前台实现，目前在后台过滤。)
});


/**
 * 操作tab标签
 */
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
	if (getScope("StoreReportModule").loadingData) {
		return;
	}
	if ($(e.target).attr('href') == "#storeRecordDetailList") {
		getScope("StoreReportModule").dataListType = 'storeRecordDetailList';
		getScope("StoreReportModule").storeReportUrl = '{{ route('admin.shop.report.allot.transfersRecordDetailList') }}';
		getScope("StoreReportModule").$apply(function (scope) {
			scope.curSearchItemArr = detailListSearchItemArr;
		});
		setGridColDisplay(detailListShowColsArr);
		getScope("StoreReportModule").searchModel.groupBy = "";
	} else if ($(e.target).attr('href') == "#groupByOrderList") {
		getScope("StoreReportModule").dataListType = 'groupByOrderList';
		getScope("StoreReportModule").storeReportUrl = '{{ route('admin.shop.report.allot.transfersRecordList') }}';
		getScope("StoreReportModule").$apply(function (scope) {
			scope.curSearchItemArr = groupByOrderListSearchItemArr;
		});
		setGridColDisplay(groupByOrderListShowColsArr);
		getScope("StoreReportModule").searchModel.groupBy = "order";
	} else if ($(e.target).attr('href') == "#groupByGoodList") {
		getScope("StoreReportModule").dataListType = 'groupByGoodList';
		getScope("StoreReportModule").storeReportUrl = '{{ route('admin.shop.report.allot.transfersGoodsList') }}';
		getScope("StoreReportModule").$apply(function (scope) {
			scope.curSearchItemArr = groupByGoodListSearchItemArr;
		});
		setGridColDisplay(groupByGoodListShowColsArr);
		getScope("StoreReportModule").searchModel.groupBy = "goods";
	} else if ($(e.target).attr('href') == "#groupByStorehouseList") {
		getScope("StoreReportModule").dataListType = 'groupByStorehouseList';
		getScope("StoreReportModule").storeReportUrl = '{{ route('admin.shop.report.allot.transfersStorehouseList') }}';
		getScope("StoreReportModule").$apply(function (scope) {
			scope.curSearchItemArr = groupByStorehouseListSearchItemArr;
		});
		setGridColDisplay(groupByStorehouseListShowColsArr);
		getScope("StoreReportModule").searchModel.groupBy = "storehouse";
	}
	// 改变businessType的标题。按单据汇总时显示为单据类型，否则显示为业务类别
	changeBusinessTypeColName(getScope("StoreReportModule").dataListType);
	// 清除列表数据
	jQuery("#list_section").jqGrid("clearGridData");
	// 查询数据
	getScope("StoreReportModule").searchList();
	// 查询汇总结果（不同tab的groupby字段不同，当有盈亏情况的查询条件时，不能共用汇总数据）
	getScope("StoreReportModule").getSumData();

	showPriceAndAmount($(e.target).attr('href'));
});


//等候提示窗口
$("#waitingDialog").dialog({
	autoOpen: false,
	show: {
		effect: "blind",
		duration: 10
	},
	position: ['middle', 200],
	width: 300,
	height: 134,
	modal: true,
	resizable: false,
	open: function () {
	},
	dialogClass: "waitingDialog"
});

/**
 * 根据系统参数内的设置判断是否显示金额和单价
 * @param 当前查询的汇总信息，如果查询的是调拨详细，则显示单价那一列
 * */
function showPriceAndAmount(url) {
	var priceTag = getScope("StoreReportModule").storeTransferOrder.price;
	if (priceTag == 'factoryPrice' || priceTag == 'tradePrice' || priceTag == 'retailPriceArea') {
		if (url === '#storeRecordDetailList') {
			jQuery("#list_section").setGridParam().showCol("price").trigger("loadGrid");
		} else {
			jQuery("#list_section").setGridParam().hideCol("price").trigger("loadGrid");
		}
		jQuery("#list_section").setGridParam().showCol("amount").trigger("loadGrid");
	} else {
		jQuery("#list_section").setGridParam().hideCol("price").trigger("loadGrid");
		jQuery("#list_section").setGridParam().hideCol("amount").trigger("loadGrid");
	}
}

/**
 * 改变businessType的标题。按单据汇总时显示为单据类型，否则显示为业务类别
 *
 * @param dataListType
 */
function changeBusinessTypeColName(dataListType) {
	var colDisplayName = '业务类别';
	if (dataListType == 'groupByOrderList') {
		colDisplayName = '单据类型';
	}
	$("#list_section").jqGrid("setLabel", 'businessType', colDisplayName, {});
}

/**
 * 将盈亏状态转换成汉字
 */
function profitStatusDecode(cellvalue, options, rowdata) {
	if (cellvalue != undefined) {
		var objData = getObject(getScope("StoreReportModule").profitStatusSeleteData, 'id', cellvalue);
		if (objData) {
			return objData.name;
		} else {
			return '';
		}
	} else {
		return '';
	}
}

/**
 * 显示“是”或者“否” 1-是 2-否
 */
function yearFromater(cellvalue, options, rowdata) {
	if (!cellvalue) {
		return '';
	} else if (parseFloat(cellvalue) - parseInt(cellvalue) == 0.5) {
		return cellvalue == '' ? '' : (parseInt(cellvalue) + '下');
	} else {
		return cellvalue == '' ? '' : (parseInt(cellvalue) + '上');
	}
}

//设置jgrid表头对齐方式
function setGridLabelAlign(gridId, colNames, alignType) {
	var colNameArr = [];
	if (colNames != undefined) {
		colNameArr = colNames.split(',');
	}
	for (var i = 0; i < colNameArr.length; i++) {
		$("#" + gridId).jqGrid("setLabel", colNameArr[i], "", {
			"text-align": alignType
		});
	}
};

//设置jgrid表头样式
function setGridLabelClass(gridId, colNames, css) {
	var colNameArr = [];
	if (colNames != undefined) {
		colNameArr = colNames.split(',');
	}
	for (var i = 0; i < colNameArr.length; i++) {
		$("#" + gridId).jqGrid("setLabel", colNameArr[i], "", css);
	}
};

//设置jgrid列是否显示
function setGridColDisplay(showColsArr) {
	jQuery("#list_section").jqGrid('destroyFrozenColumns');
	for (var i = 0; i < jqgridAllColsArr.length; i++) {
		if (contains(showColsArr, jqgridAllColsArr[i])) {
			jQuery("#list_section").setGridParam().showCol(jqgridAllColsArr[i]);
		} else {
			jQuery("#list_section").setGridParam().hideCol(jqgridAllColsArr[i]);
		}
	}
	jQuery("#list_section").jqGrid('setFrozenColumns');
}


var getChildIds = function (list, startPid) {
	var ids = startPid;

	if (startPid != undefined && startPid != '') {
		if (list != undefined && list.length > 0) {
			for (var i = 0; i < list.length; i++) {
				if (list[i]['pid'] == startPid) {
					ids = ids + ',' + getChildIds(list, list[i]['id']);
				}
			}

			return ids;
		} else {
			return startPid;
		}
	} else {
		return '';
	}

};

/**
 * 分类ID转为分类名称
 */
function categoryNamesDecode(cellvalue, options, rowdata) {
	if (cellvalue) {

		var nameTemp = getObject(allCategoryList, 'id', cellvalue);

		if (nameTemp) {
			return nameTemp.name;
		} else {
			return '';
		}

	} else {
		return '';
	}
}

/* 修复Jqgrid冻结列高度函数 */
function adjustFrozenDivHeight(listId) {
	var bdivTop = -1;

	if (navigator.userAgent.toLowerCase().match(/opera/)) {
		divTop = 0;
		bdivTop = 0;
	}
	if ($('#gview_' + listId + ' .frozen-bdiv').length > 0) {
		$('#gview_' + listId + ' .frozen-bdiv').css({
			top: $('#gview_' + listId + ' .frozen-bdiv').position().top + bdivTop
		});
	}
}

//检查每一行冻结行高度是否和未冻结行高度一致
function adjustFrozenColumnHeight(listId) {
	$('#' + listId + '_frozen tr').slice(1).each(function () {

		var frozenTdHeight = parseFloat($('td:first', this).height());
		var normalHeight = parseFloat($(' #' + listId + ' #' + $(this).attr('id')).find('td:first').height());

		// 如果冻结的列高度小于未冻结列的高度则hack之
		if (frozenTdHeight != normalHeight) {

			$('td', this).each(function () {

				/* 浏览器差异高度hack */
				var space = 0; // opera默认使用0就可以
				/*				if (navigator.userAgent.toLowerCase().match(/chrome/)) {
                                    space = 0.6;
                                } else if (navigator.userAgent.toLowerCase().match(/msie/)) {
                                    space = -0.2;
                                } else if (navigator.userAgent.toLowerCase().match(/mozilla/)) {
                                    space = 0.3;
                                }*/
				$(this).style('height', parseFloat(normalHeight + space) + "px", 'important');
				/*
				 * div.style('color', 'blue', 'important');
				 * $(this).css("cssText","height:"+parseFloat(normalHeight +
				 * space)+"px !important");
				 */
				/*
				 * if (!$(this).attr('style') ||
				 * $(this).attr('style').indexOf('height:') == -1) {
				 * $(this).attr('style', $(this).attr('style') + ";height:" +
				 * (normalHeight + space) + "px !important"); }
				 */
			});
		}
		$('#gview_' + listId + ' .ui-jqgrid-bdiv:eq(1)').style('height', $('#gview_' + listId + ' .ui-jqgrid-bdiv:first').height() + 'px', 'important');

	});

	$('#gview_' + listId + ' .frozen-bdiv').style('height', $('table#' + listId + '_frozen').height() + 'px', 'important');//避免冻结的DIV挡住列表的横向滚动条
}

/*回车事件*/
$('#searchForm').keypress(function (e) {
	if (e.keyCode == '13') {
		stopEvent(e);
		$('#searchBtn').click();
	}
});
</script>